package com.shopping.manager.service.imp;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ccj.shopping_common.pojo.TaotaoResult;
import com.ccj.shopping_common.utils.IDUtils;
import com.shopping.manager.mapper.TbItemMapper;
import com.shopping.manager.pojo.TbItem;
import com.shopping.manager.pojo.TbItemDesc;
import com.shopping.manager.pojo.TbItemExample;
import com.shopping.manager.service.ItemService;


@Service
public class ItemServiceImpl implements ItemService{
	
	@Autowired
	private TbItemMapper itemMapper;
	@Autowired
	private TbItemMapper itemDescMapper;
	
	@Override
	public TbItem getItemById(long id) {
		TbItemExample example = new TbItemExample();
		example.createCriteria().andIdEqualTo(id);
		List<TbItem> list =itemMapper.selectByExample(example );
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public int saveItem(TbItem item) {
//		// TODO Auto-generated method stub
//		Date date = new Date();
//		//获得商品id
//		long id = IDUtils.genItemId();
//		//添加商品信息
//		item.setId(id);
//		//商品状态，1-正常，2-下架，3-删除
//		item.setStatus((byte) 1);
//		item.setCreated(date);
//		item.setUpdated(date);
//		itemMapper.insert(item);
//		//添加商品描述
//		//创建TbItemDesc对象
//		TbItemDesc itemDesc = new TbItemDesc();
//		//获得一个商品id
//		itemDesc.setItemId(id);
//		itemDesc.setItemDesc(desc);
//		itemDesc.setCreated(date);
//		itemDesc.setUpdated(date);
//		//插入数据
//		itemDescMapper.insert(itemDesc);

		return 0;
	}
	
	
	/**
	 * service 
	 */
	@Override
	public TaotaoResult createItem(TbItem item) {
		// TODO Auto-generated method stub
		Long itemId=IDUtils.genItemId();
		Date date = new Date();

		item.setId(itemId);
		item.setStatus((byte) 1);
		item.setCreated(date);
		item.setUpdated(date);
		
		itemMapper.insert(item);
		return TaotaoResult.ok();
	}
	
	

}
